home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-m-s.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  6KB  |  245 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-re-mat.h"
  34. #include "ov-scalar.h"
  35. #include "ov-typeinfo.h"
  36. #include "op-m-s.h"
  37. #include "ops.h"
  38. #include "xdiv.h"
  39. #include "xpow.h"
  40.  
  41. // matrix by scalar ops.
  42.  
  43. static octave_value
  44. add (const octave_value& a1, const octave_value& a2)
  45. {
  46.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  47.  
  48.   return octave_value (v1.matrix_value () + v2.double_value ());
  49. }
  50.  
  51. static octave_value
  52. sub (const octave_value& a1, const octave_value& a2)
  53. {
  54.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  55.  
  56.   return octave_value (v1.matrix_value () - v2.double_value ());
  57. }
  58.  
  59. static octave_value
  60. mul (const octave_value& a1, const octave_value& a2)
  61. {
  62.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  63.  
  64.   return octave_value (v1.matrix_value () * v2.double_value ());
  65. }
  66.  
  67. static octave_value
  68. div (const octave_value& a1, const octave_value& a2)
  69. {
  70.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  71.  
  72.   double d = v2.double_value ();
  73.  
  74.   if (d == 0.0)
  75.     gripe_divide_by_zero ();
  76.  
  77.   return octave_value (v1.matrix_value () / d);
  78. }
  79.  
  80. static octave_value
  81. pow (const octave_value& a1, const octave_value& a2)
  82. {
  83.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  84.  
  85.   return xpow (v1.matrix_value (), v2.double_value ());
  86. }
  87.  
  88. static octave_value
  89. ldiv (const octave_value& v1, const octave_value&)
  90. {
  91.   gripe_nonconformant ("operator \\", v1.rows (), v1.columns (), 1, 1);
  92.   return octave_value ();
  93. }
  94.  
  95. #define BOOL_OP(OP, EMPTY_RESULT) \
  96.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (), \
  97.          double, s, v2.double_value (), \
  98.          m (i, j) OP s, EMPTY_RESULT)
  99.  
  100. static octave_value
  101. lt (const octave_value& a1, const octave_value& a2)
  102. {
  103.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  104.  
  105.   BOOL_OP (<, Matrix ());
  106. }
  107.  
  108. static octave_value
  109. le (const octave_value& a1, const octave_value& a2)
  110. {
  111.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  112.  
  113.   BOOL_OP (<=, Matrix ());
  114. }
  115.  
  116. static octave_value
  117. eq (const octave_value& a1, const octave_value& a2)
  118. {
  119.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  120.  
  121.   BOOL_OP (==, 0.0);
  122. }
  123.  
  124. static octave_value
  125. ge (const octave_value& a1, const octave_value& a2)
  126. {
  127.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  128.  
  129.   BOOL_OP (>=, Matrix ());
  130. }
  131.  
  132. static octave_value
  133. gt (const octave_value& a1, const octave_value& a2)
  134. {
  135.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  136.  
  137.   BOOL_OP (>, Matrix ());
  138. }
  139.  
  140. static octave_value
  141. ne (const octave_value& a1, const octave_value& a2)
  142. {
  143.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  144.  
  145.   BOOL_OP (!=, 1.0);
  146. }
  147.  
  148. static octave_value
  149. el_mul (const octave_value& a1, const octave_value& a2)
  150. {
  151.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  152.  
  153.   return octave_value (v1.matrix_value () * v2.double_value ());
  154. }
  155.  
  156. static octave_value
  157. el_div (const octave_value& a1, const octave_value& a2)
  158. {
  159.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  160.  
  161.   double d = v2.double_value ();
  162.  
  163.   if (d == 0.0)
  164.     gripe_divide_by_zero ();
  165.  
  166.   return octave_value (v1.matrix_value () / d);
  167. }
  168.  
  169. static octave_value
  170. el_pow (const octave_value& a1, const octave_value& a2)
  171. {
  172.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  173.  
  174.   return elem_xpow (v1.matrix_value (), v2.double_value ());
  175. }
  176.  
  177. static octave_value
  178. el_ldiv (const octave_value& a1, const octave_value& a2)
  179. {
  180.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  181.  
  182.   return x_el_div (v2.double_value (), v1.matrix_value ());
  183. }
  184.  
  185. static octave_value
  186. el_and (const octave_value& a1, const octave_value& a2)
  187. {
  188.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  189.  
  190.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  191.                  double, s, v2.double_value (),
  192.          m (i, j) && s, Matrix ());
  193. }
  194.  
  195. static octave_value
  196. el_or (const octave_value& a1, const octave_value& a2)
  197. {
  198.   CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
  199.  
  200.   MX_SC_BOOL_OP (Matrix, m, v1.matrix_value (),
  201.                  double, s, v2.double_value (),
  202.          m (i, j) || s, Matrix ());
  203. }
  204.  
  205. static octave_value
  206. assign (octave_value& a1, const octave_value_list& idx,
  207.     const octave_value& a2)
  208. {
  209.   CAST_BINOP_ARGS (octave_matrix&, const octave_scalar&);
  210.  
  211.   v1.assign (idx, v2.matrix_value ());
  212.   return octave_value ();
  213. }
  214.  
  215. void
  216. install_m_s_ops (void)
  217. {
  218.   INSTALL_BINOP (add, octave_matrix, octave_scalar, add);
  219.   INSTALL_BINOP (sub, octave_matrix, octave_scalar, sub);
  220.   INSTALL_BINOP (mul, octave_matrix, octave_scalar, mul);
  221.   INSTALL_BINOP (div, octave_matrix, octave_scalar, div);
  222.   INSTALL_BINOP (pow, octave_matrix, octave_scalar, pow);
  223.   INSTALL_BINOP (ldiv, octave_matrix, octave_scalar, ldiv);
  224.   INSTALL_BINOP (lt, octave_matrix, octave_scalar, lt);
  225.   INSTALL_BINOP (le, octave_matrix, octave_scalar, le);
  226.   INSTALL_BINOP (eq, octave_matrix, octave_scalar, eq);
  227.   INSTALL_BINOP (ge, octave_matrix, octave_scalar, ge);
  228.   INSTALL_BINOP (gt, octave_matrix, octave_scalar, gt);
  229.   INSTALL_BINOP (ne, octave_matrix, octave_scalar, ne);
  230.   INSTALL_BINOP (el_mul, octave_matrix, octave_scalar, el_mul);
  231.   INSTALL_BINOP (el_div, octave_matrix, octave_scalar, el_div);
  232.   INSTALL_BINOP (el_pow, octave_matrix, octave_scalar, el_pow);
  233.   INSTALL_BINOP (el_ldiv, octave_matrix, octave_scalar, el_ldiv);
  234.   INSTALL_BINOP (el_and, octave_matrix, octave_scalar, el_and);
  235.   INSTALL_BINOP (el_or, octave_matrix, octave_scalar, el_or);
  236.  
  237.   INSTALL_ASSIGNOP (octave_matrix, octave_scalar, assign);
  238. }
  239.  
  240. /*
  241. ;;; Local Variables: ***
  242. ;;; mode: C++ ***
  243. ;;; End: ***
  244. */
  245.